<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace longbingcore\permissions;

abstract class PermissionAbstract
{
    public $tabbarKey;
    public $adminMenuKey;
    public $apiPaths;
    public $saasKey;
    protected $sassValue;
    protected $uniacid;
    public $infoConfig = ["auth_platform" => true, "auth_is_platform_check" => true, "auth_is_saas_check" => true];
    public $info = [];
    public static $pAuthConfig;
    public function __construct(int $uniacid, ?int $tabbarKey, $adminMenuKey, $saasKey, array $apiPaths, $infoConfigOptions = [])
    {
        $this->tabbarKey = $tabbarKey;
        $this->adminMenuKey = $adminMenuKey;
        $this->saasKey = $saasKey;
        $this->apiPaths = $apiPaths;
        $this->uniacid = $uniacid;
        if(!empty($infoConfigOptions)) {
            $this->infoConfig = array_merge($this->infoConfig, $infoConfigOptions);
        } else {
            $adminModelListInfo = config("app.AdminModelList");
            $saas_auth_admin_model_list = $adminModelListInfo["saas_auth_admin_model_list"];
            if(array_key_exists($this->adminMenuKey, $saas_auth_admin_model_list)) {
                $this->infoConfig = array_merge($this->infoConfig, $saas_auth_admin_model_list[$this->adminMenuKey]);
            }
        }
        $this->info = $this->getModelInfo($this->adminMenuKey);
        $this->sassValue = $this->getAuthVaule($this->saasKey);
    }
    public function getModelInfo($model_name)
    {
        $infoDataPath = APP_PATH . $model_name . "/info/Info.php";
        $infoData = [];
        if(file_exists($infoDataPath)) {
            $infoData = (include $infoDataPath);
        }
        return $infoData;
    }
    public abstract function sAuth();
    public abstract function pAuth();
    public abstract function cAuth($user_id);
    public function getSaasValue() : int
    {
        return $this->sassValue;
    }
    public static function this($uniacid)
    {
        return new static($uniacid);
    }
    public function getPAuthConfig() : ?array
    {
        if(isset(self::$pAuthConfig[$this->uniacid])) {
            return self::$pAuthConfig[$this->uniacid];
        }
        try {
            $cardauth2_config_exist = \think\facade\Db::query("show tables like \"%longbing_cardauth2_config%\"");
            if(empty($cardauth2_config_exist)) {
                return NULL;
            }
            $pAuthConfig = \think\facade\Db::name("longbing_cardauth2_config")->where([["modular_id", "=", $this->uniacid]])->find();
        } catch (\think\db\exception\DataNotFoundException $notFoundException) {
            return NULL;
        } catch (\think\db\exception\ModelNotFoundException $modelNotFoundException) {
            return NULL;
        } catch (\think\db\exception\DbException $exception) {
            return NULL;
        }
        self::$pAuthConfig[$this->uniacid] = $pAuthConfig;
        return $pAuthConfig;
    }
    public function getAuthVaule($saasAuthKey, $defaultAuthNumber = -1, $update = 0)
    {
        $returnNumber = 0;

        $auth = SaasAuthConfig::getSAuthConfig($this->uniacid, $update);
        if($auth) {
            $authkey = array_column($auth, 1, 0);
        } else {
            $authkey = [];
        }
        if(array_key_exists($saasAuthKey, $authkey)) {
            $returnNumber = intval($authkey[$saasAuthKey]);
            $returnNumber = $returnNumber == 0 ? 0 : $returnNumber;
        } else {
            $returnNumber = $defaultAuthNumber;
        }
        return $returnNumber;
    }
    public function getAuthPlatform()
    {
        return $this->infoConfig["auth_platform"];
    }
    public function getAuthIsPlatformCheck()
    {
        return $this->infoConfig["auth_is_platform_check"];
    }
    public function getAuthIsSaasCheck()
    {
        return $this->infoConfig["auth_is_saas_check"];
    }
    public function getAuthNumber()
    {
        return $this->getAuthVaule($this->saasKey);
    }
}

?>